<!-- 不合格评审 质检员 -->
<script lang="ts">
export default {
  name: "appraise"
};
</script>
<script setup lang="ts">
import { reactive, ref, nextTick, onMounted } from "vue";
import { changeHeight } from "/@/utils/public.mixin";
import { VXETable, VxeTableInstance } from "vxe-table";
import {
  queryAll,
  queryReviewDetail,
  deleteUnqualifiedReviewBillById
} from "/@/api/quality/appraise";
import { getAllUsers } from "/@/api/basic/user";
import { successMessage } from "/@/utils/message";
import { queryUserByToken } from "/@/api/basic/user";
import { useRoute } from "vue-router";
import { dateFormatYMD } from "/@/utils/date";
import { ElForm } from "element-plus";
const route = useRoute();
const routeName = route.name as string;
const page = reactive({
  pageNum: 1,
  pageRow: 20,
  totalResult: 0
});
const table = reactive({
  loading: false,
  tableData: [] as any[],
  tableHeight: 0, //表格高度
  listQuery: {
    bomCode: ""
  }
});
const xTable = ref({} as VxeTableInstance);
// 查询
const searchEvent = () => {
  const data: any = {};
  data.pageNum = page.pageNum;
  data.pageRow = page.pageRow;
  data.bomCode = table.listQuery.bomCode;
  data.stepStatus = [10];
  queryAll(data).then((res: any) => {
    if (res.code === 0) {
      table.tableData = res.data.list;
      page.totalResult = res.data.total;
    }
    table.loading = false;
  });
};

// 分页发生改变时会触发该事件
const handlePageChange = ({ currentPage, pageSize }) => {
  page.pageNum = currentPage;
  page.pageRow = pageSize;
  searchEvent();
};
//质检员数据
const procedure = reactive({
  NewOne: [],
  SrcOne: [],
  NewTwo: [],
  SrcTwo: [],
  NewThree: [],
  SrcThree: [],
  inseTitle: "",
  loading: false,
  submitLoading: false,
  filterName: "",
  selectRow: null,
  showEdit: false,
  tableData: [] as any[],
  userData: [] as any[],
  userInfo: {} as any,
  formData: {
    bhgDesc: "",
    bhgFxGw: "",
    bhgCzyj: "",
    bhgNum: "",
    billNo: "",
    bomCode: "",
    bomName: "",
    fxrQz: "",
    fxrQzDate: "",
    zjr: "",
    qiTaskId: 0,
    zlzgQz: "",
    zlzgQzDate: "",
    id: 0,
    psrId: "",
    psrQz: "",
    fxzyz: "",
    fxGs: "",
    jyyQz: "",
    fjGs: "" as any,
    fgfxDesc: "",
    zlzgQz2: "",
    zlzgQzDate2: "",
    bhgStatus: ""
  }
});

//判定按钮
const detailsEvent = (row: any) => {
  Object.keys(procedure.formData).forEach(key => {
    procedure.formData[key] = row[key] ? row[key] : procedure.formData[key];
  });
  procedure.formData.qiTaskId = row.id;
  procedure.formData.id = row.id;
  procedure.selectRow = row;

  procedure.showEdit = true;
  queryReviewDetail(row.id).then((res: any) => {
    //评审图片回显
    procedure.NewOne = res.data.entityPic;
    procedure.SrcOne = [];
    procedure.NewOne.forEach(item => {
      procedure.SrcOne.push(item.fileurl);
    });
    //文员图片回显
    procedure.NewTwo = res.data.audit;
    procedure.SrcTwo = [];
    procedure.NewTwo.forEach(item => {
      procedure.SrcTwo.push(item.fileurl);
    });
    //8D报告图片回显
    procedure.NewThree = res.data.d8Report;
    // procedure.SrcThree = [];
    // procedure.NewThree.forEach(item => {
    //   procedure.SrcThree.push(item.fileurl);
    // });
  });
};
const getUsers = () => {
  getAllUsers().then((res: any) => {
    if (res.code === 0) {
      procedure.userData = res.data;
    }
  });
};
const queryUser = () => {
  queryUserByToken().then((res: any) => {
    if (res.code == 0) {
      procedure.userInfo = res.data;
    }
  });
};
//质检员取消
const handleClose = () => {
  nextTick(() => {
    procedure.showEdit = false;
    procedure.formData = {
      bhgDesc: "",
      bhgFxGw: "",
      bhgCzyj: "",
      bhgNum: "",
      billNo: "",
      bomCode: "",
      bomName: "",
      fxrQz: "",
      fxrQzDate: "",
      zjr: "",
      qiTaskId: 0,
      zlzgQz: "",
      zlzgQzDate: "",
      id: 0,
      psrId: "",
      psrQz: "",
      fxzyz: "",
      fxGs: "",
      jyyQz: "",
      fjGs: "" as any,
      fgfxDesc: "",
      zlzgQz2: "",
      zlzgQzDate2: "",
      bhgStatus: ""
    };
  });
};
//作废
const invalidEvent = async (row: any) => {
  const type = await VXETable.modal.confirm("是否作废?");
  if (type !== "confirm") {
    return;
  }
  deleteUnqualifiedReviewBillById(row.id).then((res: any) => {
    successMessage("作废成功");
    searchEvent();
  });
};
// mounted
onMounted(() => {
  nextTick(() => {
    // 将表格和工具栏进行关联
    searchEvent();
    getUsers();
    queryUser();
    table.tableHeight = changeHeight();
  });
});
</script>

<template>
  <div>
    <!-- 工具栏 -->
    <vxe-form :data="table.listQuery">
      <vxe-form-item title="料号" field="bomCode" :item-render="{}">
        <template #default="{ data }">
          <vxe-input
            v-model="data.bomCode"
            placeholder="请输入料号"
          ></vxe-input>
        </template>
      </vxe-form-item>
      <vxe-form-item>
        <template #default>
          <vxe-button
            icon="fa fa-search"
            status="primary"
            @click="searchEvent"
            v-auth="routeName + ':search'"
            >查询</vxe-button
          >
        </template>
      </vxe-form-item>
    </vxe-form>
    <!-- 列表 -->
    <vxe-table
      ref="xTable"
      class="mytable-style"
      border
      show-header-overflow
      show-overflow
      :row-config="{ isHover: true }"
      :print-config="{}"
      :export-config="{}"
      :height="table.tableHeight"
      :data="table.tableData"
    >
      <vxe-column type="seq" title="序号" width="60"></vxe-column>
      <vxe-column field="createdTime" title="时间" min-width="160"></vxe-column>
      <vxe-column field="bomCode" title="料号" min-width="130"></vxe-column>
      <vxe-column
        field="billNo"
        title="不合格评审单编号"
        min-width="160"
      ></vxe-column>
      <vxe-column
        field="bhgFxGw"
        title="不合格发现角色"
        min-width="130"
      ></vxe-column>
      <vxe-column field="fxrQz" title="发现人" min-width="100"></vxe-column>
      <vxe-column field="fxrQzDate" title="发现日期" min-width="100">
        <template #default="{ row }">
          {{ row.fxrQzDate ? row.fxrQzDate.split(" ")[0] : "" }}
        </template>
      </vxe-column>
      <vxe-column
        field="bhgDesc"
        title="不合格品描述"
        min-width="200"
      ></vxe-column>
      <vxe-column field="status" title="状态" min-width="70">
        <template #default="{ row }">
          <el-tag type="success" effect="dark" v-if="row.isDelFlag == 1"
            >正常</el-tag
          >
          <el-tag type="danger" effect="dark" v-if="row.isDelFlag == 0"
            >作废</el-tag
          >
        </template>
      </vxe-column>
      <vxe-column title="操作" width="180" fixed="right">
        <template #default="{ row }">
          <vxe-button
            type="text"
            icon="fa fa-eye"
            @click="detailsEvent(row)"
            v-auth="routeName + ':checkDetail'"
            >查看详情</vxe-button
          >
          <vxe-button
            type="text"
            icon="fa fa-trash-o"
            v-if="row.completed != 1 && row.isDelFlag == 1"
            @click="invalidEvent(row)"
            v-auth="routeName + ':edit'"
            >作废</vxe-button
          >
        </template>
      </vxe-column>
    </vxe-table>

    <!-- 分页 -->
    <vxe-pager
      perfect
      @page-change="handlePageChange"
      v-model:current-page="page.pageNum"
      v-model:page-size="page.pageRow"
      :total="page.totalResult"
      :page-sizes="[10, 20, 50, 100, 300]"
      :layouts="[
        'PrevJump',
        'PrevPage',
        'Number',
        'NextPage',
        'NextJump',
        'Sizes',
        'FullJump',
        'Total'
      ]"
    >
    </vxe-pager>
    <!--文员弹框 -->
    <vxe-modal
      v-model="procedure.showEdit"
      title="不合格评审单"
      width="1000"
      height="800"
      min-width="700"
      min-height="800"
      :loading="procedure.submitLoading"
      resize
      showFooter
      destroy-on-close
      @close="handleClose"
    >
      <template #default>
        <el-form
          ref="insertForm"
          id="dialogForm"
          :model="procedure.formData"
          label-align="right"
          label-width="170px"
        >
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item prop="billNo" label="不合格评审单编号">
                {{ procedure.formData.billNo }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="16" :lg="16" :xl="16">
              <el-form-item prop="bhgNum" label="不合格数量">
                {{ procedure.formData.bhgNum }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item prop="bomCode" label="料号">
                {{ procedure.formData.bomCode }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="16" :lg="16" :xl="16">
              <el-form-item prop="bomName" label="品名">
                {{ procedure.formData.bomName }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item prop="bhgFxGw" label="发现角色">
                {{ procedure.formData.bhgFxGw }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="16" :lg="16" :xl="16">
              <el-form-item prop="fxrQz" label="发现人">
                {{ procedure.formData.fxrQz }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item prop="fxrQzDate" label="发现日期">
                {{
                  procedure.formData.fxrQzDate &&
                  dateFormatYMD(procedure.formData.fxrQzDate)
                }}
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="16" :lg="16" :xl="16">
              <el-form-item prop="zjr" label="质检人">
                {{ procedure.formData.zjr }}
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item prop="bhgDesc" label="不合格品描述">
                {{ procedure.formData.bhgDesc }}
              </el-form-item>
            </el-col>
            <!-- 评审实物图片回显 -->
            <el-col :span="24">
              <el-form-item label="实物图片">
                <div class="demo-image__preview">
                  <span
                    v-for="item in procedure.NewOne"
                    :key="item.id"
                    style="margin: 0px 10px"
                  >
                    <el-image
                      style="width: 100px; height: 100px"
                      :src="item.fileurl"
                      :preview-src-list="procedure.SrcOne"
                    >
                    </el-image>
                  </span>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                v-if="procedure.selectRow.stepStatus > 20"
                prop="psrQz"
                label="技术员"
              >
                {{ procedure.formData.psrQz }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="procedure.selectRow.stepStatus > 20"
              :xs="24"
              :sm="12"
              :md="8"
              :lg="8"
              :xl="8"
            >
              <el-form-item prop="zlzgQz" label="质量经理">
                {{ procedure.formData.zlzgQz }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="procedure.selectRow.stepStatus > 20"
              :xs="24"
              :sm="12"
              :md="16"
              :lg="16"
              :xl="16"
            >
              <el-form-item prop="zlzgQzDate" label="签字日期">
                {{
                  procedure.formData.zlzgQzDate &&
                  dateFormatYMD(procedure.formData.zlzgQzDate)
                }}
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="procedure.selectRow.stepStatus > 30">
              <el-form-item prop="bhgStatus" label="不合格判定">
                <el-button size="mini" type="primary">
                  {{ procedure.formData.bhgStatus }}
                </el-button>
              </el-form-item>
              <el-form-item prop="bhgCzyj" label="不合格品处理意见">
                {{ procedure.formData.bhgCzyj }}
              </el-form-item>
            </el-col>
            <!-- 返工、返修-----开始 -->
            <el-col
              v-if="
                (procedure.selectRow.bhgStatus === '返工' ||
                  procedure.selectRow.bhgStatus === '返修') &&
                procedure.selectRow.stepStatus > 40
              "
              :span="24"
            >
              <el-form-item prop="fgfxDesc" label="返工、返修校验记录">
                {{ procedure.formData.fgfxDesc }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="
                (procedure.selectRow.bhgStatus === '返工' ||
                  procedure.selectRow.bhgStatus === '返修') &&
                procedure.selectRow.stepStatus > 40
              "
              :xs="24"
              :sm="12"
              :md="12"
              :lg="12"
              :xl="12"
            >
              <el-form-item prop="fxzyz" label="返修人">
                {{ procedure.formData.fxzyz }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="
                (procedure.selectRow.bhgStatus === '返工' ||
                  procedure.selectRow.bhgStatus === '返修') &&
                procedure.selectRow.stepStatus > 40
              "
              :xs="24"
              :sm="12"
              :md="12"
              :lg="12"
              :xl="12"
            >
              <el-form-item prop="fxGs" label="返修工时">
                {{ procedure.formData.fxGs }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="
                (procedure.selectRow.bhgStatus === '返工' ||
                  procedure.selectRow.bhgStatus === '返修') &&
                procedure.selectRow.stepStatus > 40
              "
              :xs="24"
              :sm="12"
              :md="12"
              :lg="12"
              :xl="12"
            >
              <el-form-item prop="jyyQz" label="复检人">
                {{ procedure.formData.jyyQz }}
              </el-form-item>
            </el-col>
            <el-col
              v-if="
                (procedure.selectRow.bhgStatus === '返工' ||
                  procedure.selectRow.bhgStatus === '返修') &&
                procedure.selectRow.stepStatus > 40
              "
              :xs="24"
              :sm="12"
              :md="12"
              :lg="12"
              :xl="12"
            >
              <el-form-item prop="fjGs" label="复检工时">
                {{ procedure.formData.fjGs }}
              </el-form-item>
            </el-col>
            <!-- 返工、返修-----结束 -->

            <!-- OA审批信息开始 ----- OA审批信息相关图片回显 -->
            <el-col :span="24" v-if="procedure.selectRow.stepStatus > 40">
              <el-form-item label="OA审批信息">
                <div class="demo-image__preview">
                  <span
                    v-for="item in procedure.NewTwo"
                    :key="item.id"
                    style="margin: 0px 10px"
                  >
                    <el-image
                      style="width: 100px; height: 100px"
                      :src="item.fileurl"
                      :preview-src-list="procedure.SrcTwo"
                    >
                    </el-image>
                  </span>
                </div>
              </el-form-item>
            </el-col>
            <!-- OA审批信息-----结束 -->
            <!-- 8D报告回显 -->
            <el-col
              :span="24"
              v-if="
                procedure.formData.bhgStatus === '报废' &&
                procedure.selectRow.stepStatus > 40
              "
            >
              <el-form-item label="8D报告">
                <!-- 文件列表 -->
                <transition-group
                  class="upload-file-list el-upload-list el-upload-list--text"
                  name="el-fade-in-linear"
                  tag="ul"
                >
                  <li
                    :key="file.uid"
                    class="el-upload-list__item ele-upload-list__item-content"
                    v-for="file in procedure.NewThree"
                  >
                    <el-link
                      :href="file.fileurl || ''"
                      :underline="false"
                      target="_blank"
                    >
                      <span class="el-icon-document">
                        {{ file.name ? file.name : file.filename }}
                      </span>
                    </el-link>
                  </li>
                </transition-group>
              </el-form-item>
            </el-col>
            <!-- 8D报告-----结束 -->
            <!-- 质量主管-----开始 -->
            <el-col
              :xs="24"
              :sm="12"
              :md="16"
              :lg="16"
              :xl="16"
              v-if="procedure.selectRow.completed === 1"
            >
              <el-form-item prop="zlzgQz2" label="质量主管">
                {{ procedure.formData.zlzgQz2 }}
              </el-form-item>
            </el-col>
            <el-col
              :xs="24"
              :sm="12"
              :md="8"
              :lg="8"
              :xl="8"
              v-if="procedure.selectRow.completed === 1"
            >
              <el-form-item prop="zlzgQzDate2" label="签字日期">
                {{
                  procedure.formData.zlzgQzDate2 &&
                  dateFormatYMD(procedure.formData.zlzgQzDate2)
                }}
              </el-form-item>
            </el-col>
            <!-- 质量主管-----结束 -->
          </el-row>
        </el-form>
      </template>
      <template #footer>
        <vxe-button @click="handleClose">取 消</vxe-button>
      </template>
    </vxe-modal>
  </div>
</template>
<style scoped>
@import url("/@/style/dialog.css");
</style>
<style>
.mytable-style .vxe-body--column.col-blue {
  background-color: #60b8ff;
  color: #fff;
}
.mytable-style .vxe-body--column.col-orange {
  background-color: #f56c6c;
  color: #fff;
}
</style>
<style lang="scss" scoped>
.vxe-input + .vxe-button,
.vxe-input + .vxe-button--dropdown,
.vxe-button + .vxe-button,
.vxe-button + .vxe-button--dropdown {
  margin-left: 0;
}

.vxe-toolbar.size--medium {
  padding: 10px;
}

.vxe-table--render-default.size--medium {
  margin-top: 12px;
}

.vxe-button.size--medium.type--button {
  margin-left: 1em;
  height: 32px;
}

.text-model {
  &:hover {
    cursor: pointer;
  }
}
:deep(.redText .el-form-item__label) {
  color: red;
}
.demo-image__preview {
  margin-top: 20px;
  margin-left: 50px;
  margin-bottom: 20px;
}
</style>
